﻿@model PaginatedList<Contoso_University.Models.Student>

@{
    ViewData["Title"] = "学生管理";
}

<h1>学生管理</h1>

<p>
    <a asp-action="Create" class="btn btn-primary">新建学生</a>
</p>

<form asp-action="Index" method="get" class="mb-3">
    <div class="input-group">
        <input type="text" name="SearchString" value="@ViewData["CurrentFilter"]" class="form-control" placeholder="按姓名搜索..." />
        <button type="submit" class="btn btn-outline-secondary">搜索</button>
        <a asp-action="Index" class="btn btn-outline-secondary">清除</a>
    </div>
</form>

<table class="table-striped table">
    <thead>
        <tr>
            <th>
                <a asp-action="Index" asp-route-sortOrder="@ViewData["NameSortParm"]">
                    姓
                </a>
            </th>
            <th>
                名
            </th>
            <th>
                <a asp-action="Index" asp-route-sortOrder="@ViewData["DateSortParm"]">
                    入学日期
                </a>
            </th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.LastName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.FirstName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.EnrollmentDate)
                </td>
                <td>
                    <a asp-action="Edit" asp-route-id="@item.ID" class="btn btn-sm btn-outline-primary">编辑</a>
                    <!--<a asp-action="Details" asp-route-id="@item.ID" class="btn btn-sm btn-outline-info">详情</a>-->
                    <a asp-action="Delete" asp-route-id="@item.ID" class="btn btn-sm btn-outline-danger">删除</a>
                </td>
            </tr>
        }
    </tbody>
</table>

@{
    var prevDisabled = !Model.HasPreviousPage ? "disabled" : "";
    var nextDisabled = !Model.HasNextPage ? "disabled" : "";
}

<nav aria-label="分页导航">
    <ul class="pagination justify-content-center">
        <li class="page-item @prevDisabled">
            <a asp-action="Index"
               asp-route-sortOrder="@ViewData["CurrentSort"]"
               asp-route-pageNumber="@(Model.PageIndex - 1)"
               asp-route-currentFilter="@ViewData["CurrentFilter"]"
               class="page-link">
                上一页
            </a>
        </li>
        <li class="page-item @nextDisabled">
            <a asp-action="Index"
               asp-route-sortOrder="@ViewData["CurrentSort"]"
               asp-route-pageNumber="@(Model.PageIndex + 1)"
               asp-route-currentFilter="@ViewData["CurrentFilter"]"
               class="page-link">
                下一页
            </a>
        </li>
    </ul>
</nav> 